'use strict'

const { Controller } = require('egg')

class WallController extends Controller {
  // 获取墙列表
  async getList() {
    const { ctx, service } = this
    const result = await service.wall.getList()
    ctx.apiSuccess(result)
  }
  // 获取墙列表(admin)
  async getListAdmin() {
    const { ctx, app } = this
    const result = await app.model.Wall.findAll()
    ctx.apiSuccess(result)
  }
  // 修改墙的标语(admin)
  async updateSlogan() {
    const { ctx, service } = this
    // 参数验证
    ctx.validate({
      id: { type: 'int', required: true, desc: '墙的id' },
      slogan: { type: 'string', required: true, range: { min: 1, max: 200 }, desc: '标语' }
    })
    const { id, slogan } = ctx.request.body
    const result = await service.wall.updateSlogan(id, slogan)
    ctx.apiSuccess(result)
  }
  // 添加墙(admin)
  async createWall() {
    const { ctx, app } = this
    const { title, slogan } = ctx.request.body
    const result = await app.model.Wall.create({ title, slogan })
    ctx.apiSuccess(result)
  }
}

module.exports = WallController
